//作业1
console.log("作业1：");
var str =
      `
        fjskfjsl fjkdsjfkls fjklsfjlsd127.0.0.1fjksldfjafjio
        jfk192.168.1.101sljfs fsdjfkldsfjsklfsklffjoijfoiafa
        sfjs fed jfjf jf sdjfsi jfi jafis function dd ( ) { }a
        fjsdiajf iosa function abc(){} jfisjad fjsaiofjaoissfa
        ddedfds
      `
console.log("初始字符串如下：");
console.log(str);

var str_rx = /\d{1,3}\.\d{1,3}.\d{1,3}.\d{1,3}/g;
var str_rx2 = /(function\s+[a-zA-Z\_\$][\w\_\$]*\s*\(\s*\)\s*\{\s*\})/g;
console.log("字符串中匹配的IP为：");

//方法1---成功，结果为二元字符串数组
let result = str.match(str_rx);
console.log(result);

console.log("字符串中匹配的函数为：");
let result2 = str.match(str_rx2);
console.log(result2);

console.log("-------------------------")
console.log("-------------------------")


//作业2
console.log("作业2");
function fn(arr1, arr2) {
  let arr = [];
  for (let i = 0; i < Math.min(arr1.length,arr2.length); i++){
    arr.push(arr1[i]);
    arr.push(arr2[i]);
  }
  if(arr1.length < arr2.length){
    for (let i = arr1.length; i < arr2.length; i++){
      arr.push(arr2[i]);
    }
  }
  else{
    for (let i = arr2.length; i < arr1.length; i++){
      arr.push(arr1[i]);
    }
  }
  return console.log(arr);
}

fn([1,2,3], [4,5,6,7,8]);

console.log("-------------------------")
console.log("-------------------------")

//作业3
console.log("作业3");
function shaizi(num = 1){
  let sz = 0;
  for(let i = 0; i < num; i++){
    sz += Math.ceil(Math.random()*6)
  }
  return console.log(sz);
}

shaizi(2);

console.log("-------------------------")
console.log("-------------------------")

//作业4
console.log("作业4");
function sleep(time){
  return new Promise((resolve)=>{
    setTimeout(() => resolve(), time);
  });
}

async function test(){

  console.log("start");
  await sleep(3000);
  console.log("3 seconds passed");
  console.log("continue");
  await sleep(5000);
  console.log("5 seconds passed");
}

test();
